package com.qf.personal.controller;


import com.qf.common.base.result.RespResult;
import com.qf.personal.entiy.Car;
import com.qf.personal.entiy.CarManage;
import com.qf.personal.service.CarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "用车申请")
@RestController
@RequestMapping("/my/car")
public class CarController {

    @Resource
    private CarService carService;

    @GetMapping("/select")
    @ApiOperation("查询所有车辆")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult<List<CarManage>> select() {
        return carService.selectCar();
    }

    @PutMapping("/add")
    @ApiOperation("添加用车")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult<String> add(Car car) {
        return carService.addUseCar(car);
    }

    @PutMapping("/all")
    @ApiOperation("查询用车")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult<List<Car>> select(int eId) {
        return carService.selectAll(eId);
    }

    @PutMapping("/search")
    @ApiOperation("搜索")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult<List<Car>> search(Car car) {
        return carService.searchCar(car);
    }

    @PutMapping("/delete")
    @ApiOperation("删除")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult<String> delete(Long id) {
        return carService.deleteById(id);
    }
}
